#include <bits/stdc++.h>

const int MAXN = 100005;

using namespace std;

struct Edge {
	int to, nxt;
} E[MAXN << 1];

int H[MAXN], tot;

inline void Add_Edge (const int u, const int v) {
	E[++ tot] = {v, H[u]}, H[u] = tot;
	E[++ tot] = {u, H[v]}, H[v] = tot;
}

int Siz[MAXN], Chd[MAXN], Son[MAXN], Dp[MAXN][2];

inline void Init (const int x, const int f) {
	Siz[x] = 1;
	for (int i = H[x]; i; i = E[i].nxt)
		if (E[i].to != f) 
			Init (E[i].to, x), Siz[x] += Siz[E[i].to], ++ Chd[x],
			Siz[E[i].to] > Siz[Son[x]] ? Son[x] = E[i].to : 0;
}

inline void Update (const int val1, const int val2, const int pos, int * max1, int * max2, int * pos1, int * pos2) {
	if (val1 > max1[0]) max1[1] = max1[0], max1[0] = val1, pos1[1] = pos1[0], pos1[0] = pos;
	else if (val1 > max1[1]) max1[1] = val1, pos1[1] = pos;
	if (val2 > max2[0]) max2[1] = max2[0], max2[0] = val2, pos2[1] = pos2[0], pos2[0] = pos;
	else if (val2 > max2[1]) max2[1] = val2, pos2[1] = pos;
}

inline void DFS (const int x, const int f) {
	if (Siz[x] == 1) return Dp[x][0] = 1, Dp[x][1] = 0, void ();
	int Max[2][2] = {{0, 0}, {0, 0}}, Pos[2][2] = {{0, 0}, {0, 0}};
	for (int i = H[x]; i; i = E[i].nxt) 
		if (E[i].to != f)
			DFS (E[i].to, x), Update (Dp[E[i].to][0], Dp[E[i].to][1], E[i].to, Max[0], Max[1], Pos[0], Pos[1]);
	
	if (Max[0][1]) Dp[x][0] = Max[0][0] + Max[0][1] + 1;
	else Dp[x][0] = max (Max[1][0] + 1, (Siz[x] - 1 - Max[0][0] > 0) ? Max[0][0] + 2 : Max[0][0]);
	if (Chd[x] > 1) Dp[x][1] = 1 + ((Pos[0][0] == Pos[1][0]) ? max (Max[0][0] + Max[1][1], Max[0][1] + Max[1][0]) : (Max[0][0]  + Max[1][0]));
	else Dp[x][1] = Max[0][0] + 1;
	
//	if (Siz[x] > 45000) cerr << x << ' ' << (Dp[x][0] < Dp[x][1]) << ' ' << Dp[x][0] << ' ' << Dp[x][1] << ' ' << Siz[x] << ' ' << Chd[x] << '\n';
}

int N;

int u, v;

int main () {
	
	freopen ("bird.in", "r", stdin);
	freopen ("bird.out", "w", stdout);
		
	cin >> N;
	
	for (int i = 2; i <= N; ++ i)
		cin >> u >> v, Add_Edge (u, v);
	
	Init (1, 0), DFS (1, 0);
	
	cerr << Dp[1][0] << ' ' << Dp[1][1] << '\n';
	cout << max (Dp[1][0], Dp[1][1]) << '\n';
		
	return 0;
}
